#include <stdio.h> #define M sizeof(unsigned int)*8 //进制转换 int trans(int n,int d,char *str){ char s[16]="0123456789ABCDEF"; int j,i=M; char buf[i+1]; buf[M]='\0'; if(d<2||d>16){ return 0; } while(n!=0){ buf[--i]=s[n%d]; n/=d; } for(j=0;(*(str+j)=buf[i])!='\0';j++,i++); return j; } int main(){ int i; //要转换的数 char s[M+1]; int d=2; //进制 for(i=0;i<10;i++){ if(trans(i,2,s)) printf("(%d)10==(%s)%d\n",i,s,d); } return 0; }